package perf.graph;

import perf.data.Binary;
import perf.data.Run;
import perf.data.Sourcefile;
import edu.uci.ics.jung.graph.SparseGraph;

public class GraphGenerator {

	public static SparseGraph<Vertex,Edge> getGraph( Run run ) {
		SparseGraph<Vertex,Edge> graph = new SparseGraph<Vertex, Edge>();
		
		VertexRun runvertex = new VertexRun( run );
		
		graph.addVertex( runvertex );
		for (Binary b : run.siblings() ) {
			VertexBinary binvertex = new VertexBinary(b, runvertex); 
			graph.addVertex( binvertex );
			graph.addEdge(new Edge(0), runvertex, binvertex );
			
			for (Sourcefile sf : b.siblings() ) {
				VertexSourcefile sfvertex = new VertexSourcefile(sf, binvertex);
				
				graph.addVertex(sfvertex);
				graph.addEdge(new Edge(0), binvertex, sfvertex);
			}
		}
		
		return graph;
	}
}
